package com.yutel.phone.binh.data;

import java.util.ArrayList;
import java.util.HashMap;

import android.util.Log;

import com.yutel.phone.binh.data.net.VideoHelper;
import com.yutel.phone.binh.data.vo.VideoStream;

public class VideoQuery {
	private final String TAG = "VideoQuery";
	public VideoStream qiyi(String url) {
		try {
			int index=0;
			VideoHelper vh = new VideoHelper();
			String xml = vh.queryVideoXml(url);
//			Log.i(TAG,"xml_url="+xml);
			VideoStream vs=vh.queryVideoStream(xml);
//			for (String item : vs.getFileUrl()) {
//				Log.i(TAG, "file_url=" + item);
//			}
			vs.setParam(new HashMap<String, String>());
			vh.queryTime(vs);
			String timeT=vs.getParam().get("time_t");
			long mtime = Integer.valueOf(timeT) ^ 2519219136l;
			//查询地址
			vs.setPlayUrl(new ArrayList<String>());
			for(String item:vs.getFileUrl()) {
//				Log.i(TAG,"src_url="+item);
				String videoURL = item.substring(0, item.lastIndexOf("."))
						+ ".hml?v=" + mtime;
//				Log.i(TAG,"videoURL="+videoURL);
				vh.buildUrl(vs,videoURL);
				StringBuffer sb=new StringBuffer();
				sb.append(vs.getParam().get("play_l"));
				sb.append("-mohoDurations-").append(vs.getFileDuration().get(index));
				sb.append("-mohoAllDurations-").append(vs.getTotalDuration());
				vs.getPlayUrl().add(sb.toString());
			}
			return vs;
		} catch (Exception e) {
			Log.e(TAG, "videoStream()", e);
			return null;
		}
	}
}
